import pygame

class WorldObject(pygame.sprite.Sprite):
    ''' This class is the super class for all objects that exist 
        on the grid. It itself is a subclass of the pygame sprite 
        class, allowing for everything that is on the grid to be seen
        on the gui. It also contains the basic properties that
        each object on the grid needs to have such as isSolid
        and isFixed.
    '''
    
    def __init__(self, loc, gridsize, col = (0, 0, 0), solid = False):
        pygame.sprite.Sprite.__init__(self)
        self.gridsize = gridsize
        self.color = col
        self.solid = solid
        self.fixed = False
        self.image = pygame.Surface([gridsize,gridsize])
        self.image.fill(self.color)
        self.rect = self.image.get_rect()
        self.rect.topleft = [loc[0]*self.gridsize, loc[1]*self.gridsize]
        self.loc = loc
        self.actionQueue = []
        
    
    def addTuple(self,t1,t2):
        ''' Adds two tuples together '''
        sum = []
        for i in range(0,len(t1)):
            sum.append(t1[i]+t2[i])
        return sum            
    
    def isSolid(self):
        return self.solid   
    
    def isMovable(self):
        return self.fixed   
    
class Goal(WorldObject):
    ''' The goal object represents a goal position
        on the grid. Currently nanobots are suppossed
        to move to goal positions but eventually any
        thing could be defined as a goal.
    '''
    def __init__(self, loc, gridsize):
        WorldObject.__init__(self, loc, gridsize)
        self.fixed = True   
        self.solid = False 
    
    def __repr__(self):
        return "Goal"
    
class Block(WorldObject):
    ''' A block that the nanobots have to push to a goal '''
    
    def __init__(self, loc, gridsize):
        WorldObject.__init__(self, loc, gridsize, (255,0,0))
        self.solid = True
        self.masterBoard = None
        
    def __repr__(self):
        return "Block"
    
    def push(self, pusherLoc):
        newloc = (2*self.loc[0]-pusherLoc[0], 2*self.loc[1]-pusherLoc[1])
        if self.masterBoard.validLoc(newloc):
            self.loc = newloc
            return True
        
        return False
    
class Switch(WorldObject):
    ''' A simple switch that the nanobot can press.
        !!!This was never used!!!
    '''
    
    def __init__(self, loc, gridsize):
        WorldObject.__init__(self, loc,gridsize,(125,125,0))
        self.solid = True
        self.masterBoard = None
        self.active = False
        
    def __repr__(self):
        return "Switch"
    
    def push(self, pusherLoc):
        self.active = not self.active
        return False

class Wall(WorldObject):
    ''' !!!Not used!!! '''
    
    def __init__(self, loc, gridsize):
        WorldObject.__init__(self, loc, gridsize, (100,100,100))
        self.fixed = True
        self.solid = True
    
    def __repr__(self):
        return "Wall"
